/*
 * Reles.java
 *
 * Created on 3 de febrero de 2013, 15:14
 */

package camara;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;

/**
 *
 * @author  ivan
 */
public class Reles extends javax.swing.JFrame {
    public KMtronic hiloReles;
    
    public void RelesSetIp(String ip){
        hiloReles.sIP=ip;
        hiloReles.start();
    }
    /** Creates new form Reles */
    public Reles() {
        initComponents();
        // Se hace el arranque
        hiloReles = new KMtronic(this,"192.168.0.120");
        //hiloReles.start();
        this.jButton1.setSize(100,24);
        this.jButton2.setSize(100,24);
        this.jButton3.setSize(100,24);
        this.jButton4.setSize(100,24);
        this.jButton5.setSize(100,24);
        this.jButton6.setSize(100,24);
        this.jButton7.setSize(100,24);
        this.jButton8.setSize(100,24);
        this.jButton9.setSize(100,24);
        this.jButton10.setSize(100,24);
        this.jButton11.setSize(100,24);
        this.jButton12.setSize(100,24);
        PonEstadoReles(1,0);
        PonEstadoReles(2,0);
        PonEstadoReles(3,0);
        PonEstadoReles(4,0);
        
        
        
    }
    public void PonEstadoReles(int rele, int estado){
        boolean quePoner;
        if (estado==1) quePoner=true;
        else quePoner=false;
        if (rele==1){
            if (estado==2){
                try {
                    this.jLuz1.setOpaque(true);
                    this.invalidate();
                    this.repaint();
                    Thread.sleep(500);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Reles.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            this.jLuz1.setOpaque(quePoner);
        }
        else if (rele==2){
            if (estado==2){
                try {
                    this.jLuz2.setOpaque(true);
                    this.invalidate();
                    this.repaint();
                    Thread.sleep(500);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Reles.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            this.jLuz2.setOpaque(quePoner);
        }
        else if (rele==3){
            if (estado==2){
                try {
                    this.jLuz3.setOpaque(true);
                    this.invalidate();
                    this.repaint();
                    Thread.sleep(500);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Reles.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            this.jLuz3.setOpaque(quePoner);
        }
        else if (rele==4){
            if (estado==2){
                try {
                    this.jLuz4.setOpaque(true);
                    this.invalidate();
                    this.repaint();
                    Thread.sleep(500);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Reles.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            this.jLuz4.setOpaque(quePoner);
        }
        this.invalidate();
        this.repaint();
        
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLuz2 = new javax.swing.JLabel();
        jLuz3 = new javax.swing.JLabel();
        jLuz4 = new javax.swing.JLabel();
        jLuz1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton12 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setResizable(false);

        jLayeredPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLayeredPane1.setAlignmentX(0.0F);
        jLayeredPane1.setAlignmentY(0.0F);
        jLayeredPane1.setMaximumSize(new java.awt.Dimension(800, 514));

        jLuz2.setBackground(new java.awt.Color(255, 51, 51));
        jLuz2.setOpaque(true);
        jLuz2.setBounds(412, 260, 20, 10);
        jLayeredPane1.add(jLuz2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLuz3.setBackground(new java.awt.Color(255, 51, 51));
        jLuz3.setOpaque(true);
        jLuz3.setBounds(527, 260, 20, 10);
        jLayeredPane1.add(jLuz3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLuz4.setBackground(new java.awt.Color(255, 51, 51));
        jLuz4.setOpaque(true);
        jLuz4.setBounds(640, 260, 20, 10);
        jLayeredPane1.add(jLuz4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLuz1.setBackground(new java.awt.Color(255, 51, 51));
        jLuz1.setOpaque(true);
        jLuz1.setBounds(300, 260, 20, 10);
        jLayeredPane1.add(jLuz1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel5.setFont(new java.awt.Font("Dialog", 1, 12));
        jLabel5.setText("RELE 4");
        jLabel5.setOpaque(true);
        jLabel5.setPreferredSize(new java.awt.Dimension(50, 16));
        jLabel5.setBounds(635, 120, 50, 16);
        jLayeredPane1.add(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel4.setFont(new java.awt.Font("Dialog", 1, 12));
        jLabel4.setText("RELE 3");
        jLabel4.setOpaque(true);
        jLabel4.setPreferredSize(new java.awt.Dimension(50, 16));
        jLabel4.setBounds(520, 120, 50, 16);
        jLayeredPane1.add(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel3.setFont(new java.awt.Font("Dialog", 1, 12));
        jLabel3.setText("RELE 2");
        jLabel3.setOpaque(true);
        jLabel3.setPreferredSize(new java.awt.Dimension(50, 16));
        jLabel3.setBounds(400, 120, 50, 16);
        jLayeredPane1.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setFont(new java.awt.Font("Dialog", 1, 12));
        jLabel2.setText("RELE 1");
        jLabel2.setOpaque(true);
        jLabel2.setBounds(280, 120, 50, 16);
        jLayeredPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton12.setText("Apagar");
        jButton12.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton12MouseClicked(evt);
            }
        });
        jButton12.setBounds(610, 220, 100, 24);
        jLayeredPane1.add(jButton12, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton11.setText("Apagar");
        jButton11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton11MouseClicked(evt);
            }
        });
        jButton11.setBounds(495, 220, 90, 24);
        jLayeredPane1.add(jButton11, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton10.setText("Apagar");
        jButton10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton10MouseClicked(evt);
            }
        });
        jButton10.setBounds(375, 220, 90, 24);
        jLayeredPane1.add(jButton10, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton9.setText("Apagar");
        jButton9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton9MouseClicked(evt);
            }
        });
        jButton9.setBounds(260, 220, 100, 24);
        jLayeredPane1.add(jButton9, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton8.setText("Encender");
        jButton8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton8MouseClicked(evt);
            }
        });
        jButton8.setBounds(610, 180, 90, 24);
        jLayeredPane1.add(jButton8, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton7.setText("Encender");
        jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton7MouseClicked(evt);
            }
        });
        jButton7.setBounds(495, 180, 90, 24);
        jLayeredPane1.add(jButton7, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton6.setText("Encender");
        jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton6MouseClicked(evt);
            }
        });
        jButton6.setBounds(375, 180, 100, 24);
        jLayeredPane1.add(jButton6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton5.setText("Encender");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton5MouseClicked(evt);
            }
        });
        jButton5.setBounds(260, 180, 100, 24);
        jLayeredPane1.add(jButton5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton4.setText("Pulsar");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton4MouseClicked(evt);
            }
        });
        jButton4.setBounds(610, 140, 90, 24);
        jLayeredPane1.add(jButton4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton3.setText("Pulsar");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });
        jButton3.setBounds(495, 140, 100, 24);
        jLayeredPane1.add(jButton3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton2.setText("Pulsar");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });
        jButton2.setBounds(375, 140, 90, 24);
        jLayeredPane1.add(jButton2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton1.setText("Pulsar");
        jButton1.setMaximumSize(new java.awt.Dimension(70, 24));
        jButton1.setPreferredSize(new java.awt.Dimension(80, 24));
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.setBounds(260, 140, 100, 24);
        jLayeredPane1.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/camara/board.jpg"))); // NOI18N
        jLabel1.setText("jLabel1");
        jLabel1.setBounds(10, 10, 750, 510);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(87, 87, 87)
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 799, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(89, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 534, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(39, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
        hiloReles.pulsadorRele(1);
    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton5MouseClicked
        // TODO add your handling code here:
        hiloReles.setRele(1);
    }//GEN-LAST:event_jButton5MouseClicked

    private void jButton9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton9MouseClicked
        // TODO add your handling code here:
        hiloReles.resetRele(1);
    }//GEN-LAST:event_jButton9MouseClicked

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        // TODO add your handling code here:
        hiloReles.pulsadorRele(2);
    }//GEN-LAST:event_jButton2MouseClicked

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
        // TODO add your handling code here:
        hiloReles.pulsadorRele(3);
    }//GEN-LAST:event_jButton3MouseClicked

    private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseClicked
        // TODO add your handling code here:
        hiloReles.pulsadorRele(4);
    }//GEN-LAST:event_jButton4MouseClicked

    private void jButton6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton6MouseClicked
        // TODO add your handling code here:
        hiloReles.setRele(2);
    }//GEN-LAST:event_jButton6MouseClicked

    private void jButton7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton7MouseClicked
        // TODO add your handling code here:
        hiloReles.setRele(3);
    }//GEN-LAST:event_jButton7MouseClicked

    private void jButton8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton8MouseClicked
        // TODO add your handling code here:
        hiloReles.setRele(4);
    }//GEN-LAST:event_jButton8MouseClicked

    private void jButton10MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton10MouseClicked
        // TODO add your handling code here:
        hiloReles.resetRele(2);
    }//GEN-LAST:event_jButton10MouseClicked

    private void jButton11MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton11MouseClicked
        // TODO add your handling code here:
        hiloReles.resetRele(3);
    }//GEN-LAST:event_jButton11MouseClicked

    private void jButton12MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton12MouseClicked
        // TODO add your handling code here:
        hiloReles.resetRele(4);
    }//GEN-LAST:event_jButton12MouseClicked
  
    
    
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Reles().setVisible(true);
             
    
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JLabel jLuz1;
    private javax.swing.JLabel jLuz2;
    private javax.swing.JLabel jLuz3;
    private javax.swing.JLabel jLuz4;
    // End of variables declaration//GEN-END:variables
    
}
